import 'package:flutter/material.dart';
import 'package:untitled/utils/SnackBarHepler.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      scaffoldMessengerKey: ScaffoldMessengerGlobalKey,
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  //0 男  1 女
  int _selectGender = 0;

  int _selectNew = 0;
  @override
  Widget build(BuildContext context) {
    //脚手架
    return Scaffold(
      appBar: AppBar(
        title: Text('单选框'),
        backgroundColor: Colors.blue,
        foregroundColor: Colors.white,
      ),

      body: SizedBox.expand(
        child: Column(
          children: [
            Divider(),

            RadioGroup(
              onChanged: (int? index) {
                setState(() {
                  _selectNew = index ?? 0;
                });
              },
              groupValue: _selectNew,
              child: Column(
                children: [
                  Row(children: [Radio(value: 0), Text('数学')]),
                  Row(children: [Radio(value: 1), Text('语文')]),
                  Row(
                    children: [
                      Radio(value: 2, activeColor: Colors.red),
                      Text('英文'),
                    ],
                  ),
                ],
              ),
            ),

            Divider(),
            //
            Row(
              children: [
                Radio<int>(
                  value: 0,
                  groupValue: _selectGender,
                  onChanged: (int? value) {
                    setState(() {
                      _selectGender = value ?? 0;
                    });
                  },
                ),
                GestureDetector(
                  child: Text('男'),
                  onTap: () {
                    setState(() {
                      _selectGender = 0;
                    });
                  },
                ),
              ],
            ),
            //
            Row(
              children: [
                Radio(
                  value: 1,
                  groupValue: _selectGender,
                  onChanged: (int? value) {
                    setState(() {
                      _selectGender = value ?? 1;
                    });
                  },
                ),
                GestureDetector(
                  child: Text('女'),
                  onTap: () {
                    setState(() {
                      _selectGender = 1;
                    });
                  },
                ),
              ],
            ),

            Divider(),
            RadioListTile(
              value: 0,
              title: Text('男'),
              subtitle: Text('爱早起的年轻人'),
              secondary: Icon(Icons.man),
              activeColor: Colors.red,
              fillColor: WidgetStateProperty.all(Colors.blue),
              radioBackgroundColor: WidgetStateProperty.all(Colors.grey[100]),
              groupValue: _selectGender,
              onChanged: (int? value) {
                setState(() {
                  _selectGender = value ?? 0;
                });
              },
            ),
            RadioListTile(
              value: 1,
              title: Text('女'),
              groupValue: _selectGender,
              onChanged: (int? value) {
                setState(() {
                  _selectGender = value ?? 1;
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}
